package com.shuqi.common;

import android.os.Handler;
import android.os.Message;

import com.shuqi.interfaces.EventTypeConstants;
import com.shuqi.model.net.listener.HttpRequestErrListener;

/**
 * 抽象handler
 * 
 * @author zhangpeng
 * 
 */

public abstract class ControlHandler extends Handler {

    private HttpRequestErrListener listener = null;

    public ControlHandler(HttpRequestErrListener listener) {
        this.listener = listener;
    }

    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case EventTypeConstants.EVENT_EXC_MALFORMEDURL: // url格式异常
                if (listener != null) {
                    listener.request_url(); //
                }
                break;
            case EventTypeConstants.EVENT_EXC_PARSER: // 解析格式异常
                if (listener != null) {
                    listener.request_parse_format();
                }
                break;
            case EventTypeConstants.EVENT_EXC_IO_3:
                if (listener != null) {
                    listener.request_parse_io();//
                }
                break;
            case EventTypeConstants.EVENT_EXC_IO_2:
                if (listener != null) {
                    listener.request_content_io();//
                }
                break;
            case EventTypeConstants.EVENT_EXC_TIMEOUT:
                if (listener != null) {
                    listener.request_timeout();//
                }
                break;
            case EventTypeConstants.EVENT_EXC_NETERR:
                if (listener != null) {
                    listener.request_net_error();//
                }
                break;
        }
        super.handleMessage(msg);
    }
}
